<template>
	<!-- 手机号密码登录 -->
	<view>
		<logo></logo>
		<view class="padding flex flex-direction">
			<view class="cu-form-group margin-lr">
				<view class="title text-bold">
					+86
					<icon-font type="arrowdown" size="14" class="padding-left-xs"></icon-font>
				</view>
				<input type="number" placeholder="请输入手机号" v-model="mobile" />
			</view>
			<view class="cu-form-group margin-lr">
				<view class="title">验证码</view>
				<input type="number" placeholder="请输入验证码" v-model="code" />
				<verfication-code :mobile="mobile" type="login"></verfication-code>
			</view>
			<view class="margin flex align-center justify-between">
				<view></view>
				<navigator hover-class="none" class="text-blue text-underline" url="register">快速注册</navigator>
			</view>
			<userButton @submitEvent="logo">登录</userButton>
		</view>
		<!-- <view class="text-sm text-gray">{{ type }}</view> -->
		<annotation></annotation>
		<loading :loadModal="loadModal"></loading>
	</view>
</template>

<script>
import logo from '@/pages/access/components/logo.vue';
import annotation from '@/pages/access/components/annotation.vue';
import userButton from '@/components/user-button.vue';
import verficationCode from '@/components/verfication-code.vue';
import ajax from '@/common/request.js';
var _self; //this容器
export default {
	components: {
		logo,
		annotation,
		userButton,
		verficationCode
	},
	data() {
		return {
			mobile: '',
			code: '',
			type: '',
			loadModal: false //蒙层
		};
	},
	onLoad(options) {
		_self = this;
		if (options.type) {
			_self.type = options.type;
		}
		_self.$util.clearUserStorage();
	},
	methods: {
		logo() {
			if (_self.$util.checkMobile(_self.mobile) && _self.$util.checkCode(_self.code)) {
				const param = {
					mobilePrefix: '+86',
					mobile: _self.mobile,
					verifyCode: _self.code
				};
				_self.loadModal = true;
				_self.$http.httpNoCookieRequest('user/verifyCodeLogin', param).then(
					res => {
						_self.loadModal = false;
						if (res) {
							if (res.statusCode == 200) {
								const tmpres = res.data;
								_self.$util.clearUserStorage();
								if (tmpres._tranStatus) {
									let cookies = res.header['Set-Cookie'];
									uni.setStorageSync('JSESSIONID', cookies.split(';')[0]);
									uni.setStorageSync('login_token', tmpres._data.loginToken);
									_self.$util.setUserStorage(tmpres._data);
									_self.$util.ExistRelationId();
									uni.switchTab({
										url: '../index/main'
									});
								} else {
									let tmperror = tmpres._tranStatus ? '' : tmpres._exceptionLocalizedMessage ? tmpres._exceptionLocalizedMessage : '调用接口失败';
									_self.$util.msg(tmperror);
								}
							} else {
								_self.$util.msg('无法连接服务器');
							}
						} else {
							_self.$util.msg('系统异常res为空');
						}
					},
					error => {
						_self.$util.msg('系统异常');
					}
				);
			}
		},
	}
};
</script>

<style>
page {
	background-color: #fff;
}
</style>
